# Author：Hongjia
# 时间：

"""
批量修改文件名称
"""
def changename(py_folder_path,py_prefix,py_new_name_index):
    from os import path, listdir, rename, system
    if py_folder_path is not None and path.exists(py_folder_path):
        # 获取路径下所有的文件
        py_prefix = py_prefix + '-'
        file_name = listdir(py_folder_path)
        if len(file_name) > 0:
            file_type = None
            for name in file_name:
                old_file = path.join(py_folder_path, name)
                if path.isdir(old_file):
                    continue
                if file_type is None:
                    file_type = path.splitext(name)[1]
                new_file = path.join(py_folder_path, py_prefix + str(py_new_name_index) + file_type)
                try:
                    rename(old_file, new_file)
                except FileExistsError:
                    new_file = path.join(py_folder_path, py_prefix + str(py_new_name_index) + 'tmp_file' + file_type)
                    rename(old_file, new_file)
                py_new_name_index += 1
            # 改名完成后，把t去掉
            file_name = listdir(py_folder_path)
            for name in file_name:
                if name.find('tmp_file') != -1:
                    old_file = path.join(py_folder_path, name)
                    new_file = path.join(py_folder_path, name.replace('tmp_file', ''))
                    rename(old_file, new_file)
            py_report=("文件名批量修改成功！！！")
        else:
            py_report = ("该路径下没有文件：", py_folder_path, "请核对后重试!")
            system("pause")
    else:
        py_report = ("路径错误或路径不存在！请核对后重试!")
        system("pause")
    return [py_report]